package com.wanmait.demo.controller.workercontroller;

import com.wanmait.demo.pojo.Worker;
import com.wanmait.demo.service.WorkerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class LoginController{
    @Resource
    private WorkerService workerService;
    @PostMapping("/login")
    public String login(Worker worker, String rememberMe, HttpServletRequest request, HttpServletResponse response){
        ModelAndView modelAndView = new ModelAndView();
        Worker worker1 = workerService.findPhoneNumberAndUserPass(worker);
        if(worker1 != null){
            request.getSession().setAttribute("loginWorker",worker1);
            return "worker/index";
        }
        else{
            return "worker/login";
        }

    }
}
